<template>
	<view class="page">
		<u-navbar title="图片列表" border @leftClick="$utils.back()" placeholder>
		</u-navbar>
		<view class="body">
			<z-paging ref="paging" style="height: 100%;" :fixed="false" v-model="data" @query="query"
				:default-page-no="1" :default-page-size="20">
				<waterfall :rList='rList' :lList='lList' @del='del' />
			</z-paging>
		</view>
	</view>
</template>

<script>
	import waterfall from './components/waterfall'
	export default {
		components: {
			waterfall
		},
		data() {
			return {
				loading: true,
				data: []
			}
		},
		computed: {
			lList() {
				return this.data.filter((item, index) => {
					if (this.data.length % 2 != 0) {
						if (index == 0) return true
					}
					if (index % 2 != 0) return true
				})
			},
			rList() {
				return this.data.filter((item, index) => {
					if (this.data.length % 2 == 0) {
						if (index == 0) return true
					} else {
						if (index == 0) return false
					}
					if (index % 2 == 0) return true
				})
			}
		},
		methods: {
			del(id) {
				this.data = this.data.filter(item => item.id != id)
			},
			query(page, size) {
				let obj = {
					page,
					size
				}
				uni.showLoading({
					title: '加载中 ...'
				})
				this.$api_company.Image.List(obj).then(res => {
					uni.hideLoading()
					let arr = res.data.images.data
					arr = arr.map((item, index) => {
						return {
							...item,
							height: 476
						}
					})
					this.$refs.paging.complete(arr)
					this.loading = false
				}).catch(err => {
					uni.$u.toast(err.message)
					this.loading = false
					uni.hideLoading()
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		height: 100vh;
		padding-bottom: calc(constant(safe-area-inset-bottom) + 10rpx);
		/* 兼容 iOS 设备 */
		padding-bottom: calc(env(safe-area-inset-bottom) + 10rpx);
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
	}

	.body {
		margin-top: 20rpx;
		flex: 1;
	}
</style>